﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Data;
using NLBS.Framework;

namespace NLBS.Views.Admin
{
    public interface IMiscAction
    {
        event EventHandler UpdateCategoryCounterHandler;
        event EventHandler UpdateArticleCounterHandler;
        event EventHandler UpdateUserCounterHandler;
        event EventHandler CleanInactiveUserAccountHandler;
        event EventHandler CleanVisitorCounterHandler;
        event EventHandler CleanGuestBookEntriesHandler;
        event EventHandler UpdateGlobalCounterHandler;
    }
    public class MiscPresenter:Presenter<IFirstContentView,IMiscAction>
    {

        public override void OnActionLoaded()
        {
            this.Action.UpdateCategoryCounterHandler += new EventHandler(Action_UpdateCategoryCounterHandler);
            this.Action.UpdateArticleCounterHandler += new EventHandler(Action_UpdateArticleCounterHandler);
            this.Action.UpdateUserCounterHandler += new EventHandler(Action_UpdateUserCounterHandler);
            this.Action.CleanGuestBookEntriesHandler += new EventHandler(Action_CleanGuestBookEntriesHandler);
            this.Action.CleanInactiveUserAccountHandler += new EventHandler(Action_CleanInactiveUserAccountHandler);
            this.Action.CleanVisitorCounterHandler += new EventHandler(Action_CleanVisitorCounterHandler);
            this.Action.UpdateGlobalCounterHandler += new EventHandler(Action_UpdateGlobalCounterHandler);
            base.OnActionLoaded();
        }

        void Action_UpdateGlobalCounterHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().UpdateGlobalCounter();
            ContentCache.Instantiate().Clear();
        }

        void Action_CleanVisitorCounterHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().CleanVisitorCounter();
            ContentCache.Instantiate().Clear();
        }

        void Action_CleanInactiveUserAccountHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().CleanInactiveUserAccount();
            ContentCache.Instantiate().Clear();
        }

        void Action_CleanGuestBookEntriesHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().CleanGuestBookEntries();
            ContentCache.Instantiate().Clear();
        }

        void Action_UpdateUserCounterHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().UpdateUserCounter();
            ContentCache.Instantiate().Clear();
        }

        void Action_UpdateArticleCounterHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().UpdateArticleCounter();
            ContentCache.Instantiate().Clear();
        }

        void Action_UpdateCategoryCounterHandler(object sender, EventArgs e)
        {
            DbProvider.Instance().UpdateCategoryCounter();
            ContentCache.Instantiate().Clear();
        }
        
    }


}
